<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>监听</title>
    <script src="./js/vue.js"></script>
</head>
<body>
    <div id="app">
        <!-- 监听温度变化 -->
         <h1>当前气温:<span>{{temperature}}</span>℃</h1>
        <input type="text" v-model="temperature"/>℃
       <!-- 监听输入框内容变化 展示提示 -->

    </div>
</body>
</html>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            temperature:10
        },
        methods: {
            
        },
        watch: {
            temperature: function(newValue, oldValue) {
                console.log('当前温度:', newValue, '旧温度:', oldValue)
                if(newValue > 30) {
                    alert('当前温度过高,请注意降温！')
                }else if(newValue < 5) {
                    alert('当前温度过低,请及时加温！')
                }
            }
        }
    })
</script>